#include "GlobalGPUProgramGroup.h"

namespace egg{

    GlobalGPUProgramGroup* gGPUProgramGroup=0;

    GlobalGPUProgramGroup::GlobalGPUProgramGroup(){
        ShaderPtr postprocess=createShader("glsl/postprocess.vs",ST_Vertex);
        mPrograms["aabb"]=createProgram("glsl/aabb.vs","glsl/aabb.fs");
        mPrograms["axis"]=createProgram("glsl/axis.vs","glsl/axis.fs");
        mPrograms["blit"]=createProgram("glsl/blit.vs","glsl/blit.fs");
        mPrograms["flat"]=createProgram("glsl/flat.vs","glsl/flat.fs");
        mPrograms["skybox"]=createProgram("glsl/skybox.vs","glsl/skybox.fs");
        mPrograms["sphereMap"]=createProgram("glsl/sphereMap.vs","glsl/sphereMap.fs");
        mPrograms["refract"]=createProgram("glsl/refract.vs","glsl/refract.fs");
        mPrograms["ssao"]=createProgram(postprocess,"glsl/ssao.fs");
        mPrograms["spotLitProcess"]=createProgram(postprocess,"glsl/spotLight.fs");
        mPrograms["pointLitProcess"]=createProgram(postprocess,"glsl/spotLight.fs");
        mPrograms["directionLitProcess"]=createProgram(postprocess,"glsl/spotLight.fs");
    }

    ShaderPtr GlobalGPUProgramGroup::createShader(const string& _fileName,ShaderType _type){
        ShaderPtr ret(new Shader(_type));
        ret->load(_fileName);
        return ret;
    }

    GPUProgramPtr GlobalGPUProgramGroup::createProgram(const string& _vs,const string& _fs){
        GPUProgramPtr pro(new GPUProgram());
        pro->addShader(createShader(_vs,ST_Vertex));
        pro->addShader(createShader(_fs,ST_Fragment));
        pro->update();
        return pro;
    }

    GPUProgramPtr GlobalGPUProgramGroup::createProgram(ShaderPtr _vs,const string& _fs){
        ShaderPtr fs=createShader(_fs,ST_Fragment);
        GPUProgramPtr pro(new GPUProgram());
        pro->addShader(_vs);
        pro->addShader(createShader(_fs,ST_Fragment));
        pro->update();
        return pro;
    }

}